package com.ruoyi.project.basic.warehouse.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.basic.warehouse.domain.JcWarehouse;
import com.ruoyi.project.basic.warehouse.service.IJcWarehouseService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 仓库档案Controller
 * 
 * @author frank
 * @date 2024-08-24
 */
@RestController
@RequestMapping("/basic/warehouse/warehouse")
public class JcWarehouseController extends BaseController
{
    @Autowired
    private IJcWarehouseService jcWarehouseService;

    /**
     * 查询仓库档案列表
     */
    @PreAuthorize("@ss.hasPermi('basic/warehouse:warehouse:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcWarehouse jcWarehouse)
    {
        startPage();
        List<JcWarehouse> list = jcWarehouseService.selectJcWarehouseList(jcWarehouse);
        return getDataTable(list);
    }

    /**
     * 导出仓库档案列表
     */
    @PreAuthorize("@ss.hasPermi('basic/warehouse:warehouse:export')")
    @Log(title = "仓库档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcWarehouse jcWarehouse)
    {
        List<JcWarehouse> list = jcWarehouseService.selectJcWarehouseList(jcWarehouse);
        ExcelUtil<JcWarehouse> util = new ExcelUtil<JcWarehouse>(JcWarehouse.class);
        util.exportExcel(response, list, "仓库档案数据");
    }

    /**
     * 获取仓库档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic/warehouse:warehouse:query')")
    @GetMapping(value = "/{jcWarehouseoid}")
    public AjaxResult getInfo(@PathVariable("jcWarehouseoid") String jcWarehouseoid)
    {
        return success(jcWarehouseService.selectJcWarehouseByJcWarehouseoid(jcWarehouseoid));
    }

    /**
     * 新增仓库档案
     */
    @PreAuthorize("@ss.hasPermi('basic/warehouse:warehouse:add')")
    @Log(title = "仓库档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcWarehouse jcWarehouse)
    {
        return toAjax(jcWarehouseService.insertJcWarehouse(jcWarehouse));
    }

    /**
     * 修改仓库档案
     */
    @PreAuthorize("@ss.hasPermi('basic/warehouse:warehouse:edit')")
    @Log(title = "仓库档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcWarehouse jcWarehouse)
    {
        return toAjax(jcWarehouseService.updateJcWarehouse(jcWarehouse));
    }

    /**
     * 删除仓库档案
     */
    @PreAuthorize("@ss.hasPermi('basic/warehouse:warehouse:remove')")
    @Log(title = "仓库档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{jcWarehouseoids}")
    public AjaxResult remove(@PathVariable String[] jcWarehouseoids)
    {
        return toAjax(jcWarehouseService.deleteJcWarehouseByJcWarehouseoids(jcWarehouseoids));
    }
}
